package pathfinding.grid.astar;

import pathfinding.core.Location;
import pathfinding.core.astar.SortedLocationList;


public class GridSortedLocationList implements SortedLocationList{
	
	private MinHeap minHeap;
	
	public GridSortedLocationList(){
		minHeap = new MinHeap();
	}
	
	public int getSize(){
		return minHeap.size();
	}
	
	@Override
	public boolean hasNext() {
		return minHeap.size() > 0;
	}
	
	@Override
	public void add(Location loc){
		GridLocationAstar location = (GridLocationAstar)loc;
		addInOrder(location);
	}

	@Override
	public GridLocationAstar getNext() {
		if(minHeap.size() > 0){
			return minHeap.remove();
		}
		return null; //TODO throw end of list exception
	}
	
	private void addInOrder(GridLocationAstar location){
		minHeap.add(location);
	}
	
	@Override
	public String toString(){
		String result = minHeap.size() + "";
		return result;
	}

}
